<?php

/**
 * RaiseDateFormatter class
 * Formatter for RaiseDateTime object
 *
 * @author Sam Yong
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.Core.Text.Formatter
 * @since 1.2
 */
class RaiseDateFormatter extends RaiseObject implements IRaiseFormatter {
    
    /**
     * The format of the date/time
     * @var string
     */
    private $format = '';
    
    /**
     * Create a new RaiseDateFormatter with a specific format
     * @param string $format The format to use when formatting, see sprintf()
     */
    function __construct($format) {
        $this->format = $format;
    }
    
    /**
     * Get or set the format of the date/time
     * @param string $f (optional) Set the value
     * @return string
     * @link http://php.net/date#refsect1-function.date-parameters
     */
    public function format($f = null){
        if(func_num_args() == 1){
            $this->format = $f;
        }
        return $this->format;
    }
    
    public function parse($input) {
        if(!($input instanceof RaiseDateTime)){
            $input = RaiseConvert::toDateTime($input);
        }
        return $input->toFormat($this->format);
    }

}
